﻿using System;
using System.CodeDom.Compiler;

namespace FBGraph.ClientGenerator.CodeGen
{
    public class Parameter : CodeGenObject
    {
        public Parameter(String name, Type type)
            : this(name, new TypeReference(type)) { }

        public Parameter(String name, String typeName, params TypeReference[] typeArguments)
            : this(name, new TypeReference(typeName, typeArguments)) { }

        public Parameter(String name, TypeReference type)
        {
            this.Name = name;
            this.Type = type;
        }

        public String Name { get; set; }
        public TypeReference Type { get; set; }

        public override void Write(CodeGenWriter writer)
        {
            writer.Write(this.Type);
            writer.Write(' ');
            writer.Write(this.Name);
        }

        public override Boolean Equals(Object obj)
        {
            var that = obj as Parameter;
            if (that == null) return false;
            else return
                this.Name == that.Name &&
                this.Type.Equals(that.Type);
        }

        public override Int32 GetHashCode()
        {
            return
                this.Name.GetHashCode() ^
                this.Type.GetHashCode();
        }
    }
}